#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>

using namespace std;

char buf[1024];

void print(int num[], int n)
{
	int i = n - 1;

	if(num[i] == 0)
	{
		printf("0\n");
		return;
	}

	for(;i>=0;--i)
	{
		if(num[i] >= 0)
			printf("%d", num[i]);
	}

	if(num[0])
		printf("5");
	printf("\n");
}

void remove(int n, int cnt, int num[])
{
	for(int i = n;i<10 && cnt;i += 3)
	{
		int tmp = cnt < num[i] ? cnt : num[i];
		cnt -= tmp;
		num[i] -= tmp;
	}
}
int solve()
{
	int num[10];
	int res[3];
	memset(num, 0, sizeof(num));
	memset(res, 0, sizeof(res));

	int sum = 0;
	int zflag = 1;

	for(int i = 0;buf[i];i++)
	{
		num[buf[i] - '0'] ++;
		sum += buf[i] - '0';
		res[(buf[i] - '0') % 3] ++;
	}

	int flag = 0;	// use of 5.
	if(num[0] == 0 && num[5] == 0)
	{
		printf("impossible");
		return -1;
	}
	else if(num[0] == 0)
	{
		num[5] --;
		res[2] --;
		flag = 1;
	}
	if(sum % 3 == 1)
	{
		if(res[1])
			remove(1, 1, num);
		else if(res[2] >= 2)
			remove(2, 2, num);
		else
			goto fail;
	}
	else if(sum % 3 == 2)
	{
		if(res[2])
			remove(2, 1, num);
		else if(res[1] >= 2)
			remove(1, 2, num);
		else
			goto fail;
	}

	zflag = 1;
	for(int i = 9;i>= 0;i--)
	{
		if(i > 0 && num[i])
			zflag = 0;
		if(i == 0 && zflag)
			num[i] = num[i] < 1 ? num[i] : 1;
		for(int j = 0;j<num[i];j++)
			printf("%d", i);
	}

	if(flag)
		printf("5");

	printf("\n");
	return 0;

fail:
	printf("impossible\n");
	return -1;
}

int main()
{
	freopen("data.in", "r", stdin);
	while(scanf("%s", buf) != EOF)
	{
		solve();
	}
}
